<template>
    <div class="search_category_trending">
        <div class="search_category_trending_font">
            大家都在搜
        </div>
        <div class="search_category_trending_book_item" v-for="(book, index) in trendingBooks" :key="index">
            <p class="search_catefory_trending_img">
                <img :src="book.cover_url" @click="navigateToBook(book.id)" class="search_category_trending_bookCover" />
            </p>
           
            <div class="search_category_trending_bookInfo">
                <p class="bookName2 turnRed" @click="navigateToBook(book.id)">
                    {{ book.name }}
                </p>
                <p class="bookAuthor_hot_characterCount2">
                    <span class="turnRed" @click="navigateToAuthor(book.author.author_id)"> {{ book.author.author_name }} </span>
                    <span> | </span>
                    <span> {{ book.hot_number }}热度 </span>
                    <span> | </span>
                    <span> {{ book.word_count }}字 </span>
                </p>
                <p class="bookDescription2 turnRed" @click="navigateToBook(book.id)">
                    {{ cut(book.description, 20) }}
                </p>
                <p class="bookType2">
                    关键词:
                    <span v-for="(tag, index) in book.tag.slice(0, 3)" :key="index" class="turnRed" @click="navigateToCategory(book.tag)">
                        {{ tag }}
                        <span v-if="index < book.tag.slice(0, 3).length - 1"> , </span>
                    </span>
                </p>
            </div>
        </div>
    </div>
</template>

<script setup>
import { ref, onMounted, getCurrentInstance } from 'vue'
import '@/display/bookInfo.css';
import { getTrendingBooks } from '@/apis/getTrending.js';
import { useNavigation } from '@/utils/navigate.js';
import { cut } from '@/utils/cutText.js';

const { navigateToCategory, navigateToBook, navigateToAuthor } = useNavigation(); //导入导航函数
const { proxy } = getCurrentInstance();
const trendingBooks = ref([]);

onMounted(async () => {
    trendingBooks.value = await getTrendingBooks(proxy);
});

</script>

<style scoped>
.search_category_trending {
    height: 750px;
    display: flex;
    flex-direction: column;
    border: 1px solid rgb(207, 204, 204);
    border-radius: 10px;
}

.search_catefory_trending_img {
    display: flex;
    align-items: center;
    transition: transform 0.3s ease-in-out, box-shadow 0.3s ease-in-out;
    cursor: pointer;
}

.search_catefory_trending_img:hover {
    transform: scale(1.1);
}

.search_category_trending_font {
    padding: 20px 0 10px 20px;
    font-size: 20px;
}

.search_category_trending_book_item {
    height: 150px;
    margin: 10px;
    display: flex;
}

.search_category_trending_bookCover {
    height: 100px;
    width: 75px;
    border-radius: 5px;
}

.search_category_trending_bookInfo {
    padding-left: 30px;
}
</style>